# Build the manager binary
#FROM golang:1.22 AS builder
FROM registry.cn-hangzhou.aliyuncs.com/egon-k8s-test/golang:1.22 AS builder

ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# Cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
ENV GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
RUN go mod download

# Add additional dependencies
RUN go get k8s.io/client-go/tools/remotecommand@v0.30.1 \
    k8s.io/apimachinery/pkg/util/httpstream/spdy@v0.30.1 \
    k8s.io/apimachinery/pkg/util/proxy@v0.30.1

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/

# Build
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
#FROM gcr.io/distroless/static:nonroot
FROM registry.cn-shanghai.aliyuncs.com/egon-k8s-test/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]

